<?php 
 include_once dirname(__FILE__)."/config.php";
 class formation_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_CODE_DIPLOME;
		 protected $_NOM_FORMATION;
		 protected $_LIB_FORMATION;
		 protected $_CODE_FORMATION;
		 public function get_name_table(){ return "formation";}
		 public function get_name_CODE_DIPLOME(){ return "CODE_DIPLOME";}
		 public function get_name_NOM_FORMATION(){ return "NOM_FORMATION";}
		 public function get_name_LIB_FORMATION(){ return "LIB_FORMATION";}
		 public function get_name_CODE_FORMATION(){ return "CODE_FORMATION";}
		 public function set_CODE_DIPLOME($parametre){  $this->_CODE_DIPLOME=$parametre;}	
		 public function set_NOM_FORMATION($parametre){  $this->_NOM_FORMATION=$parametre;}	
		 public function set_LIB_FORMATION($parametre){  $this->_LIB_FORMATION=$parametre;}	
		 public function set_CODE_FORMATION($parametre){  $this->_CODE_FORMATION=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_CODE_DIPLOME(){ return $this->_CODE_DIPLOME;}
		 public function get_NOM_FORMATION(){ return $this->_NOM_FORMATION;}
		 public function get_LIB_FORMATION(){ return $this->_LIB_FORMATION;}
		 public function get_CODE_FORMATION(){ return $this->_CODE_FORMATION;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 formation(
			CODE_DIPLOME,
			NOM_FORMATION,
			LIB_FORMATION)
 VALUES(
			'".$this->_CODE_DIPLOME."',
			'".$this->_NOM_FORMATION."',
			'".$this->_LIB_FORMATION."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_CODE_DIPLOME)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
CODE_DIPLOME='".$this->_CODE_DIPLOME."'";
}
if(!empty($this->_NOM_FORMATION)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
NOM_FORMATION='".$this->_NOM_FORMATION."'";
}
if(!empty($this->_LIB_FORMATION)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
LIB_FORMATION='".$this->_LIB_FORMATION."'";
}
$sql="UPDATE 
formation SET 
 ".$sql."
								WHERE CODE_FORMATION ='".$this->_CODE_FORMATION."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
formation 
 
									WHERE CODE_FORMATION ='".$this->_CODE_FORMATION."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
formation ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		CODE_DIPLOME,
		NOM_FORMATION,
		LIB_FORMATION,
		CODE_FORMATION
 FROM 
 formation";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_CODE_DIPLOME=$row->CODE_DIPLOME;
		$this->_NOM_FORMATION=$row->NOM_FORMATION;
		$this->_LIB_FORMATION=$row->LIB_FORMATION;
		$this->_CODE_FORMATION=$row->CODE_FORMATION;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>